package com.lebang.lechuangsystem.common;

import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * controller 全局异常处理
 *
 * @author hwq
 * @since 2019/5/17
 */
@Slf4j
@ControllerAdvice
public class MyControllerAdvice {

    /**
     * 全局异常捕捉处理
     *
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public JsonData errorHandler(Exception ex) {
        log.error("异常", ex);
        return Callback.fail("800", "网络异常", ex);
    }

    /* *//**
     * 拦截捕捉自定义异常 MyException.class
     * @param ex
     * @return
     *//*
    @ResponseBody
    @ExceptionHandler(value = MyException.class)
    public Map myErrorHandler(MyException ex) {
        Map map = new HashMap();
        map.put("code", ex.getCode());
        map.put("msg", ex.getMsg());
        return map;
    }*/

}
